package com.funkyfurrymonkey.load ;
import openfl.display.Bitmap;
import openfl.display.BitmapData;
import openfl.display.Sprite;

/**
 * ...
 * @author Marcos Martinez
 */
class PreloaderScreen extends Sprite
{
	private var m_bmBackground:Bitmap;
	private var m_bmProgressBar:Bitmap;
	private var m_cProgressBar:Sprite;
	private var m_cMask:Sprite;
	public function new() 
	{
		super();
	}
	
	public function destroy()
	{
		//TODO
	}
	
	public function setBackground(cBitmap:Bitmap):Void
	{
		m_bmBackground = cBitmap;	
	}
	
	public function setProgressBar(cBitmap:Bitmap):Void
	{
		m_cProgressBar =  new Sprite ();
		m_bmProgressBar = cBitmap;
		m_cProgressBar.addChild(cBitmap);
				
		m_cMask = new Sprite();
		var bm:Bitmap = new Bitmap(new BitmapData(Math.floor(cBitmap.width),Math.floor(cBitmap.height), true, 0x66ff00ff));
		m_cMask.addChild(bm);
	}
	
	public function setScreen():Void
	{
		this.addChild(m_bmBackground);
		this.addChild(m_cProgressBar);
		m_cProgressBar.mask = m_cMask;
		m_cProgressBar.addChild(m_cMask);
		m_cMask.width = 0;
	}
	
	public function moveBar(nPerc:Float):Void
	{
		var nWidht:Float = m_bmProgressBar.width * (nPerc);
		m_cMask.width = nWidht;
		
	}
	
}